/*
 * PyramideAbstractVariable.java Created on 24 avril 2007, 14:37 To change this template, choose Tools | Template Manager and open the template in the editor.
 */

package fr.limsi.seven;

import java.util.Collection;

/**
 * @author amazaud
 */
public abstract class PyramideAbstractVariableNode {
	protected double min_value = Double.MAX_VALUE;
	protected double max_value = Double.MIN_VALUE;
	protected PyramideVariable global_var;
	protected int id_node;
	protected Collection<PyramideVariableNodeModalite> modalites;

	protected PyramideAbstractVariableNode(int id_var, int id_node, String var_name) throws PyramideVariableException {
		this.id_node = id_node;

		if ((global_var = PyramideVariable.getPyramideVariable(id_var)) == null)
			throw new PyramideVariableException("Global variable no " + id_var + " doesn't exist");

		global_var.addVarNode(this, var_name);
	}

	public PyramideVariable getGlobal_var() {
		return global_var;
	}

	public double getMaxValue() {
		return max_value;
	}

	public double getMinValue() {
		return min_value;
	}

	public Collection<PyramideVariableNodeModalite> getModalites() {
		return modalites;
	}

	public int getVarID() {
		return global_var.getVarID();
	}

	public String getVarName() {
		return global_var.getVarName();
	}

	public int getVarNodeID() {
		return id_node;
	}

	public abstract int getVarType();

	@Override
	public abstract String toString();

	protected void updateGlobalVarModalite(String nom_mod, PyramideVariableNodeModalite mod) {
		Collection<PyramideAbstractVariableNode> c = global_var.getVarNode();

		if ((c.size() == 1) && c.contains(this))
			global_var.createModalite(nom_mod);

		try {
			global_var.addNodeModalite(nom_mod, mod);
		}
		catch (PyramideVariableException ex) {
			ex.printStackTrace();
		}
	}
}

// ~ Formatted by Jindent --- http://www.jindent.com
